<?

/*
*
*   Excalibur Content Management System
*   Copyright © 2008 Egor "Sontan" Kuryanovich
*
*   Based on Explay Engine v2.0 by Golovdinov Alexander
*
*   Official site: www.excms.ru
*   Contact e-mail: support@excms.ru
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
*/


header("content-type: application/rss+xml");

$SITE_get = $db->query ("SELECT * FROM site_main");
$SITE = $db->fetch_array ($SITE_get);

if (_get(2) == "comments" && _get(3) == "articles" && is_numeric(_get(4))) 
{
	$article = $db->fetch_array ($db->query ("SELECT art_header FROM ".DB_PEREFIX."_articles WHERE art_id = '".intval(_get(4))."'"));
	$header = $article['art_header'];
	if ($header == false) exit;
	print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">
<channel>
	<title><![CDATA[$header - комментарии]]></title>
	<link><![CDATA[http://{$_SERVER['HTTP_HOST']}/articles/"._get(4).".html]]></link>
	<language>ru</language>
	<generator>eXcalibur CMS Engine</generator>";

	$get_comments = $db->query ("SELECT com_id, com_uid, com_author, com_text, com_date, usr.user_name FROM ".DB_PEREFIX."_comments AS cmt
		LEFT JOIN (SELECT user_id, user_name FROM ".DB_PEREFIX."_users) AS usr ON cmt.com_uid = usr.user_id
		WHERE com_category = 'articles' AND com_idi = '".intval(_get(4))."' ORDER BY com_id");
	
	while (list($id, $uid, $author, $text, $date, $uname) = $db->fetch_row($get_comments)) 
	{
		
		$text = strip_tags(replace_symbols($text));
		print "
	<item>
		<author><![CDATA[{$author}]]></author>
		<link><![CDATA[http://{$_SERVER['HTTP_HOST']}/articles/"._get(3).".html#comment{$id}]]></link>
		<pubDate>".date("Y-m-d H:m:s", $date)."</pubDate>
		<description><![CDATA[{$text}]]></description>
	</item>";
		
	}
}

/* elseif (_get(1) == "articles" && _get(2) != "") {
	
} */

else {
	print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">
<channel>
	<title><![CDATA[".$SITE['site_name']."]]></title>
	<link><![CDATA[http://{$_SERVER['HTTP_HOST']}/]]></link>
	<description></description>
	<language>ru</language>
	<generator>Excalibur CMS Engine</generator>";
	
	(_get(2) != "") 
		? $opt = "AND art_category = '".addslashes(_get(2))."'" 
		: $opt = "";
		
	$get_arts = $db->query ("SELECT art_id, art_header, art_body, art_author, art_date, user.user_name FROM ".DB_PEREFIX."_articles AS article
	LEFT JOIN (SELECT user_id, user_name FROM ".DB_PEREFIX."_users) AS user ON user.user_id = article.art_author
	WHERE art_like_page = 'no' $opt ORDER BY art_id DESC LIMIT 0,15");	
	
	while (list($id, $header, $body, $author, $date, $user) = $db->fetch_row($get_arts)) {
		
		$body = explode ("<cut>", $body);
		($body[1] != "") 
			? $first = $body[0]."<br /><a href=\"/articles/$id.html\">читать дальше &rarr;</a>" 
			: $first = $body[0];
		
		$firts = replace_symbols ($boby);
		
		print "
	<item>
		<title><![CDATA[".htmlspecialchars($header)."]]></title>
		<link><![CDATA[http://{$_SERVER['HTTP_HOST']}/articles/$id.html]]></link>
		<pubDate>".date("Y-m-d H:m:s", $date)."</pubDate>
		<description><![CDATA[{$first}]]></description>
		<author><![CDATA[{$user}]]></author>
	</item>";
	}
}
	
print "
</channel>
</rss>";


?>
